home *** CD-ROM | disk | FTP | other *** search
- Path: news.netppl.fi!usenet
- From: Jouko Holopainen <jouko.holopainen@xnet.otm.fi>
- Newsgroups: comp.arch.arithmetic,comp.lang.c,comp.lang.c++
- Subject: Re: Access carry flag from C
- Date: Wed, 06 Mar 1996 09:01:48 +0200
- Organization: X-Net Oy
- Message-ID: <313D385C.4651@xnet.otm.fi>
- References: <4h1veoINNlns@anvil.ugrad.cs.ubc.ca> <fgrieu-0403961143580001@ppp78.micronet.fr> <4hhbt8$1d3o@b.stat.purdue.edu> <Dnssxu.JGy@cwi.nl>
- NNTP-Posting-Host: 194.136.175.71
- Mime-Version: 1.0
- Content-Type: text/plain; charset=iso-8859-1
- Content-Transfer-Encoding: 8bit
- X-Mailer: Mozilla 2.0 (Win95; I)
-
- Dik T. Winter wrote:
- >
- > In article <4hhbt8$1d3o@b.stat.purdue.edu> hrubin@b.stat.purdue.edu (Herman Rubin) writes:
- > > In article <fgrieu-0403961143580001@ppp78.micronet.fr>,
- > > Franτois Grieu <fgrieu@micronet.fr> wrote:
- > >
- > > > if (x + yl < yl) ++yh; /* test for overflow on next line */
- > > > yl += x;
- > ...
- > > Notice that in the above code, each addition must be performed twice.
-
- > Wrong. Even a mediocre compiler will optimize this away.
-
- Just for fun, let's compare carry and non-carry assembly
- (kinda x86):
- Without carry:
- mov tmp, yl
- add tmp, x
- cmp tmp, yl
- jmp lt, noadd
- inc yh
- noadd:
- mov yl, tmp
-
- With carry:
- add yl, x
- adc yh, 0
-
- See any difference?
-
- Optimizing an addition away might in fact slow down. It just
- depends whether tmp and/or x,yl,yh are register variables.
- Anyway I know of no processor where reg+reg->reg addition takes
- longer than reg->reg move.
-
- > But the code above also works on machines without carry bit.
-
- Yes. In fact, the latter cannot be produced with C
- (or any other high level language, for that matter).
- Which was the original point.
-
- @jhol
-